package jian.hamster.ui
{
	import flash.display.Shape;
	import flash.display.Sprite;
	
	import jian.hamster.controller.TimerController;
	
	/**
	 * 进度条<br>
	 * @author jianlong.chen
	 * @date 204-04-10
	 */	
	public class JProgressBar extends Sprite
	{
		private var _changeShape:Shape;
		private var _counter:int ;
		private var _fullCounter:int ;
		private var _frontColor:Number;
		private var _width:int;
		private var _height:int;
		private var _ellipseWidth:int;
		private var _ellipseHeight:int;
		
		
		
		public function JProgressBar($color:Number, $width:int, $height:int, $counter:int, $ellipseWidth:Number=6,$ellipseHeight:Number=6)
		{
			super();
			this._width = $width;
			this._height = $height;
			this._ellipseWidth = $ellipseWidth;
			this._ellipseHeight = $ellipseHeight;
			this._fullCounter = this._counter = $counter;
			this.graphics.beginFill(0xCC0000,0.8);
			this.graphics.drawRoundRect(0,0,_width,_height,_ellipseWidth,$ellipseHeight);
			this.graphics.endFill();
			_changeShape = new Shape();
			_frontColor = $color;
			_changeShape.graphics.beginFill(_frontColor,0.8);
			_changeShape.graphics.drawRoundRect(0,0,_width,_height,_ellipseWidth,$ellipseHeight);
			_changeShape.graphics.endFill();
			addChild(_changeShape);
			
			TimerController.instance.addTickerCallBack(1000,tickerHandler);
		}
		
		private function tickerHandler():void
		{
			_changeShape.graphics.clear();
			if(_counter <= 0)
			{
				_counter = _fullCounter+1;
			}
			var currentWidth:Number = ( (--_counter)/_fullCounter) * _width;
			_changeShape.graphics.beginFill(_frontColor,0.8);
			_changeShape.graphics.drawRoundRect(0,0,currentWidth,_height,_ellipseWidth,_ellipseHeight);
			_changeShape.graphics.endFill();
		}		
		
	}
}